package cn.itcast.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 版权：卓灿教育集团 版权所有
 * author :赵航
 *
 * @e-mail: zhaohangcn@gmail.com
 * time：2021/2/16
 * describe ：${TODO}
 */
public class JdbcDome2 {
    public static void main(String[] args) {
        Connection connection = null;
        Statement statement = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            String sql = "insert into account values(null,'王五',3000)";
             connection = DriverManager.getConnection("jdbc:mysql:///db3", "root", "root");

             statement = connection.createStatement();
            int count = statement.executeUpdate(sql);
            System.out.println(count);
            if (count>0){
                System.out.println("添加成功");
            }else {
                System.out.println("添加失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (statement!=null){
                try {
                    statement.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if (connection!=null){
                try {
                    connection.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
